package fi.bluepill.server.model;

import javax.persistence.*;
import java.util.HashSet;
import java.util.Set;

@Entity
public class Location extends RateableEntity {
    @OneToMany(fetch = FetchType.LAZY)
    private Set<Barcode> barcodes = new HashSet<Barcode>();

    @OneToMany(fetch = FetchType.LAZY)
    private Set<LocationBinary> binaries = new HashSet<LocationBinary>();

    @Embedded
    private LongLat longLat;


    private String ownerId;
    private String ownerUsername;


    public String getOwnerId() {
        return ownerId;
    }

    public void setOwnerId(String ownerId) {
        this.ownerId = ownerId;
    }

    public String getOwnerUsername() {
        return ownerUsername;
    }

    public void setOwnerUsername(String ownerUserName) {
        this.ownerUsername = ownerUserName;
    }

    public LongLat getLongLat() {
        return longLat;
    }

    public void setLongLat(LongLat longLat) {
        this.longLat = longLat;
    }

    public Double distance (Location otherLocation) {
        return longLat.distance(otherLocation.getLongLat());
    }

    public Double bearing (Location otherLocation) {
        return longLat.bearing(otherLocation.getLongLat());
    }

    public boolean closerThan(double meters, Location otherLocation) {
        return longLat.closerThan(meters, otherLocation.getLongLat());
    }

    public Set<LocationBinary> getBinaries() {
        return binaries;
    }

    public void addBinary(LocationBinary binary) {
        if (!binaries.contains(binary))
            binaries.add(binary);
    }
}
